/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-11-26
 * Time:17:36
 */
public enum Test2 {
    RED("red",1),BLACK("black",2),WHITE("white",3),GREEN("green",4);
    private String name;
    private int key;


     Test2 (String name,int key) {
        this.name = name;
        this.key = key;
    }

    public static Test2 getEnumKey (int key) {
        for (Test2 t: Test2.values()) {
            if(t.key == key) {
                return t;
            }
        }
        return null;
    }
    public static void main(String[] args) {
        System.out.println(getEnumKey(2));
    }
}
